package org.minos.edit.view.components
{
	import adobe.utils.CustomActions;
	import org.aswing.ASColor;
	import org.aswing.Component;
	import org.aswing.ext.Form;
	import org.aswing.JButton;
	import org.aswing.JLabel;
	import org.aswing.JTextField;
	import org.minos.edit.model.vo.ItemVO;
	import org.minos.edit.view.components.interfaces.IFile;
	
	/**
	 * ...
	 * @author Minos
	 */
	public class InitInfoPane extends Form implements IFile
	{
		private var childrenTf : JTextField;
		private var childrenBtn : JButton;
		private var infoTf : JTextField;
		private var startTf : JTextField;
		private var startBtn : JButton;
		private var winTf : JTextField;
		private var winBtn : JButton;
		private var loseTf : JTextField;
		private var loseBtn : JButton;
		
		private var _childrenAry : Array;
		
		public function InitInfoPane()
		{
			super();
			init();
		}
		
		private function init() : void
		{
			childrenTf = new JTextField( "" , 12 );
			childrenBtn = new JButton( "设置子菜单" );
			infoTf = new JTextField( "" , 30 );
			startTf = new JTextField();
			startBtn = new JButton( "浏览" );
			winTf = new JTextField();
			winBtn = new JButton( "浏览" );
			loseTf = new JTextField();
			loseBtn = new JButton( "浏览" );
			
			addSpacer();
			addSeparator();
			append( new JLabel( "初始信息: " , null , JLabel.LEFT ) );
			addSpacer();
			
			addLabelRow( childrenTf , "初始菜单: " , "开始游戏后出现的菜单" , childrenBtn );
			addLabelRow( infoTf , "操作提示: " );
			addLabelRow( startTf , "开始动画: " , "一开始播放的动画" , startBtn );
			addLabelRow( winTf , "胜利动画: " , "过关……" , winBtn );
			addLabelRow( loseTf , "失败动画: " , "失败……" , loseBtn );
		
			_childrenAry = [];
		}
		
		/**
		 *
		 * @param	c
		 * @param	text
		 * @param	toolTip
		 * @param	act
		 */
		private function addLabelRow( c : Component , text : String , toolTip : String = null , act : Component = null ) : void
		{
			var label : JLabel = new JLabel( text , null , JLabel.LEFT );
			var tip : JLabel = null;
			if ( toolTip )
			{
				tip = new JLabel( toolTip , null , JLabel.LEFT );
				tip.setForeground( ASColor.GRAY );
			}
			addRow( label , c , act , tip );
		}
		
		// ----- get ----- //
		
		public function getChildrenTf() : JTextField
		{
			return childrenTf;
		}
		
		public function getChildrenBtn() : JButton
		{
			return childrenBtn;
		}
		
		public function getInfoTf() : JTextField
		{
			return infoTf;
		}
		
		public function getStartTf() : JTextField
		{
			return startTf;
		}
		
		public function getStartBtn() : JButton
		{
			return startBtn;
		}
		
		public function getWinTf() : JTextField
		{
			return winTf;
		}
		
		public function getWinBtn() : JButton
		{
			return winBtn;
		}
		
		public function getLoseTf() : JTextField
		{
			return loseTf;
		}
		
		public function getLoseBtn() : JButton
		{
			return loseBtn;
		}
		
		public function get childrenAry() : Array
		{
			return _childrenAry;
		}
		
		public function set childrenAry( a : Array ) : void
		{
			_childrenAry = a;
		}
		
		/* INTERFACE org.minos.edit.view.components.interfaces.IFile */
		
		public function clear() : void
		{
			childrenTf.setText( "" );
			infoTf.setText( "" );
			startTf.setText( "" );
			winTf.setText( "" );
			loseTf.setText( "" );
			_childrenAry = [];
		}
		
		public function getXML() : XML
		{
			var xml : XML =     <items />;
			xml.@init = getID( _childrenAry );
			xml.@info = infoTf.getText();
			xml.@start = startTf.getText();
			xml.@win = winTf.getText();
			xml.@lose = loseTf.getText();
			return xml;
		}
		
		public function setXML( xml:Object ):void
		{
			var _xml:XML = new XML( xml );
			//init
			infoTf.setText( _xml.@info );
			startTf.setText( _xml.@start );
			winTf.setText( _xml.@win );
			loseTf.setText( _xml.@lose );
		}
		
		private function getID( ary : Array ) : Array
		{
			var ids : Array = [];
			for each ( var i : ItemVO in ary )
			{
				if ( i )
					ids.push( i.id );
			}
			return ids;
		}
		
		
	}
}